<?php

session_start();

// Include i file necessari
include('inc/config.inc.php');
include('inc/template.inc.php');
include('inc/db.inc.php');
include('inc/check.inc.php');
 
//Variabili
$on_list = '<div class="list-group">';
$off_list = '<div class="list-group">';
 
//Recupera l'elenco delle  bacheche.
if($r1 = $db -> query("SELECT * FROM boards ORDER BY board_category"))
{
	while($rd1 = $r1 -> fetch_assoc())
	{
		// Variabili
		$cat = $rd1['board_category'];
		
		if($cat == 1)
		{
			// Se la categoria � 1, inserisce la bacheca nella lista ON
			if($rd1['board_master'] == 1 AND $_SESSION['master'] == 1)
			{
				// Se la bacheca � ristretta ai master � l'utente � master, la visualizza
				$off_list .= '<a href="topics.php?board=' . $rd1['board_id'] . '" class="list-group-item" target="_self"><h4 class="list-group-item-heading">' . $rd1['board_name'] . '</h4>';
				$off_list .= '<p class="list-group-item-text">' . htmlentities($rd1['board_description']) . '</p></a>';
			} else if($rd1['board_master'] == 0)
			{
				$on_list .= '<a href="topics.php?board=' . $rd1['board_id'] . '" class="list-group-item" target="_self"><h4 class="list-group-item-heading">' . $rd1['board_name'] . '</h4>';
				$on_list .= '<p class="list-group-item-text">' . htmlentities($rd1['board_description']) . '</p></a>';
			}
		} else if($cat == 2)
		{
			// Se la categoria � 2, inserisce la bacheca nella lista OFF
			if($rd1['board_master'] == 1 AND $_SESSION['master'] == 1)
			{
				// Se la bacheca � ristretta ai master � l'utente � master, la visualizza
				$off_list .= '<a href="topics.php?board=' . $rd1['board_id'] . '" class="list-group-item" target="_self"><h4 class="list-group-item-heading">' . $rd1['board_name'] . '</h4>';
				$off_list .= '<p class="list-group-item-text">' . htmlentities($rd1['board_description']) . '</p></a>';
			} else if($rd1['board_master'] == 0)
			{
				$off_list .= '<a href="topics.php?board=' . $rd1['board_id'] . '" class="list-group-item" target="_self"><h4 class="list-group-item-heading">' . $rd1['board_name'] . '</h4>';
				$off_list .= '<p class="list-group-item-text">' . htmlentities($rd1['board_description']) . '</p></a>';
			}
		}
	}
}

$on_list .= '</div>';
$off_list .= '</div>';

// Lista delle tag speciali
$tags = array('temp_title' => $g_name, 'temp_onlist' => $on_list, 'temp_offlist' => $off_list);

// Carica il template e formatta le tag speciali
$temp = new template('style/boards.template.html');
$temp -> replace($tags);

// Visualizza l'output
echo $temp -> show();

// Chiude la connessione al database
$db -> close();

?>